#!/bin/bash
#
#  AIA
#
#  Copyright 2022 hayder majid <hayder@riseup.net>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, you can download it from here:
#  https://www.gnu.org/licenses/gpl-3.0.html
#


#Check if you run this script with root privileges
if [ "$(whoami)" != "root" ]; then
    echo "You need to be in root privileges to run this script. Exiting."
    exit 1
fi

#set the working dir
WORKDIR=$(pwd)

install(){
	if [ ! -d "/usr/lib/AIA" ]; then
	    mkdir /usr/lib/AIA;
	    cp ${WORKDIR}/{*.py,orca-autostart.desktop} /usr/lib/AIA;
	else
	    rm -rf /usr/lib/AIA/*
	    cp ${WORKDIR}/{*.py,orca-autostart.desktop} /usr/lib/AIA;
	fi
	
	if [ ! -d "/usr/share/AIA" ]; then
	    mkdir /usr/share/AIA;
	    cp -r ${WORKDIR}/translate/locale /usr/share/AIA;
	else
	    rm -rf /usr/share/AIA/locale/*;
	    cp ${WORKDIR}/translate/locale/* /usr/share/AIA/locale;
	fi
	
	if [ ! -f "/usr/share/applications/aia.desktop" ]; then
	    cp ${WORKDIR}/aia.desktop /usr/share/applications;
	else
	    cp --force ${WORKDIR}/aia.desktop /usr/share/applications;
	fi
	
	if [ ! -f "/usr/bin/AIA" ]; then
	    cp ${WORKDIR}/AIA /usr/bin/;
	else
	    cp --force ${WORKDIR}/AIA /usr/bin/;
	fi
	if [ ! -f "/usr/bin/usudo" ]; then
	    cp ${WORKDIR}/usudo /usr/bin/;
	else
	    cp --force ${WORKDIR}/usudo /usr/bin/;
	fi
	chmod +x /usr/bin/{AIA,usudo}
}

uninstall(){
	if [ -d "/usr/lib/AIA" ]; then
	    rm -rf /usr/lib/AIA;
	fi
	
	if [ -d "/usr/share/AIA" ]; then
	    rm -rf /usr/share/AIA;
	fi
	
	if [ -f "/usr/share/applications/aia.desktop" ]; then
	    rm -rf /usr/share/applications/aia.desktop;
	fi
	
	if [ -f "/usr/bin/AIA" ]; then
	    rm -rf /usr/bin/AIA;
	fi
}

#translate(){
	
	
	
#}

if [ "$1" = "help" ]; then
        echo "  This script will help you to install, uninstall or make translate for AIA"
        echo " "
        echo "  Usage this script as follows:"
        echo " "
        #echo "  sudo ./aiaFunc help|install|uninstall|translate"
        echo "  sudo ./aiaFunc help|install|uninstall"
        echo " "
        echo " "
        echo "  Examples:"
        echo " "
        echo " "
        echo "   sudo ./aiaFunc install ==> (to install AIA on your system)"
        echo " "
        echo "   sudo ./aiaFunc uninstall  ==> (to remove uninstall AIA from your system)"
        #echo " "
        #echo "   sudo ./aiaFunc  translate ==> (to generate translation files)"
        echo " "
        echo "   sudo ./aiaFunc help ==> (to show this help instructions )"

        echo " "
        echo "   for more information, you can see to official page:"
        echo "   https://www.notabug.org/hayderctee/AIA"
        echo " "

elif [ "$1" = "" ]; then
        echo "  you need to use one argument to use this script"
        echo " "
        echo "  Usage of aiaFunc is as follows:"
        echo " "
        echo "   sudo ./aiaFunc install ==> (to install AIA on your system)"
        echo " "
        echo "   sudo ./aiaFunc uninstall  ==> (to remove uninstall AIA from your system)"
        echo " "
        #echo "   sudo ./aiaFunc  translate ==> (to generate translation files)"
        echo " "
        echo " sudo ./aiaFunc help ===> for more info"
elif [ "$1" = "install" ]; then
    echo "installing AIA . . ."
    install
    echo "done"
elif [ "$1" = "uninstall" ]; then
    echo "uninstalling AIA . . ."
    echo ""
    uninstall
    echo "done"
#elif [ "$1" = "translate" ]; then
    #echo "generating translate files . . ."
    #echo ""
    #translate
fi
